<?php
/**
 * Created by PhpStorm.
 * User: yy
 * Date: 2019/4/17
 * Time: 11:29
 */

namespace app\common\validate\environmentAnalysis;

use think\Validate;

class environmentAnalysisValidate extends Validate
{
    protected $rule = [
        'start_time'                => 'require',
        'end_time'                  => 'require',
        'company_pollutant_name'    => 'require|check_company_pollutant_name:company_pollutant_name错误',
        'contribute_pollutant_name' => 'require|check_contribute_pollutant_name:contribute_pollutant_name错误',
//        'trend_type'        => 'require|check_trend_type:trend_type错误',
        'industry_id'               => 'require',
        'region_id'                 => 'require',
        'station_id'                => 'require',
        'aqi_level'                 => 'require|check_aqi_level:aqi_level错误',
        'layer_select'              => 'require',
    ];
    protected $message = [
        'start_time.require'                => '请选择开始时间',
        'end_time.require'                  => '请选择结束时间',
        'contribute_pollutant_name.require' => '请选择溯源污染物类型',
        'company_pollutant_name.require'    => '请选择污染物类型',
        'trend_type.require'                => '请选择趋势图类型',
        'industry_id.require'               => '请选择行业类型',
        'region_id.require'                 => '缺少region_id',
        'station_id.require'                => '缺少station_id',
        'aqi_level.require'                 => '请选择空气质量等级',
        'layer_select.require'              => '请选择图层',

    ];
    protected $scene = [
        'industryEmission'        => ['start_time', 'end_time', 'contribute_pollutant_name', 'station_id', 'region_id'],
        'industryEmissionTrend'   => ['start_time', 'end_time', 'company_pollutant_name', 'industry_id', 'station_id', 'region_id'],
        'industryContributeTrend' => ['start_time', 'end_time', 'contribute_pollutant_name', 'industry_id', 'station_id', 'region_id'],
        'aqiTrend'                => ['start_time', 'end_time', 'region_id', 'station_id'],
        'pollutantDay'            => ['start_time', 'end_time', 'region_id', 'station_id'],
        'primaryPollutant'        => ['start_time', 'end_time', 'region_id', 'station_id', 'aqi_level'],
    ];
    // 自定义验证规则

    /**
     * 溯源物类型判断
     * @author yy by 2019/5/25
     * @param $value
     * @param $rule
     * @param array $data
     * @param $name
     * @param $description
     * @return bool
     */
    protected function check_contribute_pollutant_name($value, $rule, $data = [], $name, $description)
    {
        if (!in_array(strtolower($value), ['so2', 'no2'])) {
            return $rule;
        } else {
            return true;
        }
    }

    /**
     * 排放量污染物类型判断
     * @author yy by 2019/5/25
     * @param $value
     * @param $rule
     * @param array $data
     * @param $name
     * @param $description
     * @return bool
     */
    protected function check_company_pollutant_name($value, $rule, $data = [], $name, $description)
    {
        if (!in_array(strtolower($value), ['so2', 'no2', 'smoke_dust'])) {
            return $rule;
        } else {
            return true;
        }
    }
//    /**
//     * 趋势图类型判断
//     * @author yy by 2019/5/9
//     * @param $value 行业排放趋势图为emission，行业贡献度趋势图为contribute
//     * @param $rule
//     * @param array $data
//     * @param $name
//     * @param $description
//     * @return bool
//     */
//    protected function check_trend_type($value, $rule, $data = [], $name, $description)
//    {
//        if (!in_array(strtolower($value), ['emission', 'contribute'])) {
//            return $rule;
//        } else {
//            return true;
//        }
//    }

    /**
     * 空气质量等级判断
     * @author yy by 2019/5/10
     * @param $value
     * @param $rule
     * @param array $data
     * @param $name
     * @param $description
     * @return bool
     */
    protected function check_aqi_level($value, $rule, $data = [], $name, $description)
    {
        if (!in_array(strtolower($value), ['轻度', '中度', '重度', '严重'])) {
            return $rule;
        } else {
            return true;
        }
    }

}
